<?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller {
    /*
    *自动执行的方法
    */
	public function _initialize()
	{
        if(!C("OPEN")){

        }

        

        //组合访问的路径
		$path = CONTROLLER_NAME.'/'.ACTION_NAME;

        //判断是否需要进行权限验证
		if(in_array($path, C('AUTH_PATH'))){
			//判断是否登录
			if(!isset($_SESSION['nikename'])){
                //没登录跳转
    		    $this->error('你还没有登录，请先登录',U('home/login/index'));
    		}
		}
		
	}
    //检测人类验证是否通过
    public function checkVercode()
    {
    	$vercode = I('post.vercode');

        if($vercode!=$_SESSION['vercode_answer']){
            $arr = array(
            'error'=>'1',
            'info'=>'人类验证不通过'
            );
            echo json_encode($arr);
            exit;
        }
    }


    public function cateTree($cateData,$fid=0)
    {
        $temp= array();
        foreach ($cateData as $v) {
            if($v['fid']==$fid){
                $v['son']=$this->cateTree($cateData, $v['id']);
                $temp[] = $v;
            }
            
        }
        return $temp;
    }

    public function autoAdd($table,$filed,$id,$num)
    {
        $sql ="Update ".$table." set ".$filed."=".$filed."+".$num." where id=".$id;

        M()->execute($sql);
    }

    public function gethots($num=10)
    {
         // var_dump(S('hots'));

         if(S('hots')){
            echo "7777";
            $this->assign('hots',S('hots'));
         }else{
            echo "88888";

            $sql ="select * from question order by answer_num desc limit 10";

            $hots = M()->query($sql);

            S('hots',$hots,3600);

            $this->assign('hots',$hots);

         }
         
    }
}